﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Fantacid303.ProcessAffinityControl.Manager.Extensions;
using System.Windows.Input;

namespace Fantacid303.ProcessAffinityControl.Manager.MainWindowViewModels
{
	/// <summary>
	/// Represents the View Model for an Configuration Entry
	/// </summary>
	partial class ConfigurationEntryViewModel : ViewModelBase
    {
		private bool isSelected;
		private string name;
		private bool _isActive;
		private ConfigurationRuleViewModel selectedRule;

		/// <summary>
		/// Initializes a new instance of the <see cref="ConfigurationEntryViewModel"/> class.
		/// </summary>
		/// <param name="configurationViewModel">The configuration view model.</param>
		public ConfigurationEntryViewModel(ConfigurationViewModel configurationViewModel)
		{
			this.ConfigurationViewModel = configurationViewModel;
			this.Rules = new ObservableCollection<ConfigurationRuleViewModel>();
			this.SetActiveAndSaveCommand = new MySetActiveCommand(this,true);
			this.SetActiveCommand = new MySetActiveCommand(this,false);
			this.DeleteCommand = new MyDeleteCommand(this);
			this.AddRuleCommand = new MyAddRuleCommand(this);
		}

		/// <summary>
		/// Gets the list of <see cref="ConfigurationRuleViewModel"/> associated with this entry.
		/// </summary>
		/// <value>The rules.</value>
		public ObservableCollection<ConfigurationRuleViewModel> Rules
		{ get; private set; }

		/// <summary>
		/// Gets the configuration view model which is the partent of this instance
		/// </summary>
		/// <value>The configuration view model.</value>
		public ConfigurationViewModel ConfigurationViewModel
		{ get; private set; }


		/// <summary>
		/// Gets or sets a value indicating whether this entry is selected.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this entry is selected; otherwise, <c>false</c>.
		/// </value>
		public bool IsSelected
		{
			get { return isSelected; }
			set
			{
				if (isSelected == value)
					return;

				isSelected = value;


				if (value)
					this.ConfigurationViewModel.SelectedTreeObject = this;

				this.OnPropertyChanged("IsSelected");
			}
		}

		/// <summary>
		/// Gets or sets the name.
		/// </summary>
		/// <value>The name.</value>
		public string Name
		{
			get { return name; }
			set
			{
				if (name == value)
					return;

				name = value;
				this.OnPropertyChanged("Name");
			}
		}

		/// <summary>
		/// Gets or sets a value indicating whether this entry is active.
		/// </summary>
		/// <value><c>true</c> if this entry is active; otherwise, <c>false</c>.</value>
		public bool IsActive
		{
			get { return _isActive; }
			set
			{
				if (_isActive == value)
					return;

				_isActive = value;
				this.OnPropertyChanged("IsActive");
			}
		}

        /// <summary>
		/// Gets or sets the selected <see cref="ConfigurationRuleViewModel"/> from/to the UI
        /// </summary>
		public ConfigurationRuleViewModel SelectedRule
		{
			get { return selectedRule; }
			set
			{
				if (selectedRule == value)
					return;

				selectedRule = value;
				this.OnPropertyChanged("Selectedrule");
			}
		}
    }
}
